package com.proxy.autoclick.clicker.valueobject;

import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;

import com.proxy.autoclick.common.util.SpringBeanUtil;
import com.proxy.autoclick.common.util.StringUtil;
import com.proxy.autoclick.ui.layout.MainFrame;

public class SearchResultItem implements Serializable{

	private static final long serialVersionUID = -5917724718628187751L;
	
	private int pageRank;
	/*
	 * /url?q=http://www.brafton.com/business-model/search-engine-optimization&amp;
	 * sa=U&amp;ei=BdpVUdXWFcbmswaW0IDoCg&amp;
	 * ved=0CCYQFjAEOEY&amp;usg=AFQjCNHm1T6JKt-tF3__8RwDRq1d4AbjHQ
	 * 
	 * */	
	private String googleLink;
	private boolean isPartial = Boolean.FALSE;
	private String requireLink;
	private String googleServer;
	private String keyword;
	private MainFrame mainFrame;
	
	public SearchResultItem()
	{
		this.mainFrame = (MainFrame) SpringBeanUtil.getSpringBean("mainFrame");
	}
	
	public int getPageRank() {
		return pageRank;
	}
	public void setPageRank(int pageRank) {
		this.pageRank = pageRank;
	}
	public String getGoogleLink() {
		return googleLink;
	}
	public void setGoogleLink(String googleLink) {
		this.googleLink = googleLink;
	}
	public boolean isPartial() {
		return isPartial;
	}
	public void setPartial(boolean isPartial) {
		this.isPartial = isPartial;
	}
	public String getRequireLink() {
		return requireLink;
	}
	public void setRequireLink(String requireLink) {
		this.requireLink = requireLink;
	}
	public String getGoogleServer() {
		return googleServer;
	}
	public void setGoogleServer(String googleServer) {
		this.googleServer = googleServer;
	}
	public String getKeyword() {
		return keyword;
	}
	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}
	public boolean isMatchRequireLink() {
		String regexString = requireLink;
		if(this.mainFrame.isParcialUrl())
		{
			URI uri = null;
			try {
				uri = new URI(requireLink);
				regexString = uri.getHost();
			} catch (URISyntaxException e) {
				e.printStackTrace();
			}
		}
		String [] regexStringArr = {regexString};
		boolean result = StringUtil.checkStringIfFollowPattern(googleLink, regexStringArr);
		return result;
	}
}
